﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

namespace DAL
{
    [Serializable]
    public class CheckRecordData
    {

        public const string WORKESIDField = @"WorkesID";

        public const string TEIDField = @"TEID";

        public const string TIMEField = @"time";

        public const string BAKField = @"bak";

        private String _WorkesID;

        private String _TEID;

        private DateTime _time;

        private String _bak;

        public String WorkesID
        {
            get { return _WorkesID; }
            set { _WorkesID = value; }
        }
        public String TEID
        {
            get { return _TEID; }
            set { _TEID = value; }
        }
        public DateTime time
        {
            get { return _time; }
            set { _time = value; }
        }
        public String bak
        {
            get { return _bak; }
            set { _bak = value; }
        }
        public CheckRecordData()
        {
            _WorkesID = "";
            _TEID = "";
            _time = DateTime.Now;
            _bak = "";
        }
    }

    public class CheckRecordDataFactory
    {
        public static CheckRecordData Construct(IDataReader reader)
        {
            CheckRecordData data = new CheckRecordData();

            try { data.WorkesID = Convert.ToString(reader["WorkesID"]); }
            catch { }

            try { data.TEID = Convert.ToString(reader["TEID"]); }
            catch { }

            try { data.time = Convert.ToDateTime(reader["time"]); }
            catch { }

            try { data.bak = Convert.ToString(reader["bak"]); }
            catch { }

            return data;
        }
        public static CheckRecordData Construct(DataTable dt)
        {
            return Construct(dt, 0);
        }
        public static CheckRecordData Construct(DataTable dt, int rowIndex)
        {
            CheckRecordData data = new CheckRecordData();

            if (dt.Rows.Count < rowIndex + 1)

                return null;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return null;

            try { data.WorkesID = Convert.ToString(dr["WorkesID"]); }
            catch { }

            try { data.TEID = Convert.ToString(dr["TEID"]); }
            catch { }

            try { data.time = Convert.ToDateTime(dr["time"]); }
            catch { }

            try { data.bak = Convert.ToString(dr["bak"]); }
            catch { }

            return data;
        }
        public static CheckRecordData Construct(DataRow dr)
        {
            CheckRecordData data = new CheckRecordData();

            try { data.WorkesID = Convert.ToString(dr["WorkesID"]); }
            catch { }

            try { data.TEID = Convert.ToString(dr["TEID"]); }
            catch { }

            try { data.time = Convert.ToDateTime(dr["time"]); }
            catch { }

            try { data.bak = Convert.ToString(dr["bak"]); }
            catch { }

            return data;
        }
    }
    public class CheckRecordDataDBOption
    {
        public static int Insert(CheckRecordData d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into CheckRecord (");
            sql.Append("WorkesID, ");
            sql.Append("TEID, ");
            sql.Append("time, ");
            sql.Append("bak");
            sql.Append(") values (");
            sql.Append("'");
            sql.Append(d.WorkesID.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.TEID.ToString());
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.time.ToString("yyyy-MM-dd HH:mm:ss"));
            sql.Append("'");
            sql.Append(", ");
            sql.Append("'");
            sql.Append(d.bak.ToString());
            sql.Append("'");
            sql.Append(")");
            return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
        }
        public static DataTable DataTableSelect()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from CheckRecord ");
            return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
        }
        public static DataSet DataSetSelect()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from CheckRecord ");
            return WFNetLib.ADO.SQLServerOP.DataSetSQL(sql.ToString());
        }
        public static SqlDataReader ReaderSelect(CheckRecordData d)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from CheckRecord ");
            return WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL(sql.ToString());
        }
    }
}